home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / RadioBox.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.6 KB  |  136 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.Checkbox;
  4. import java.awt.CheckboxGroup;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.io.IOException;
  8. import java.util.Vector;
  9. import symantec.itools.db.pro.ProjBinder;
  10. import symantec.itools.db.pro.ProjLink;
  11. import symantec.itools.db.pro.RelationView;
  12. import symjava.sql.SQLException;
  13.  
  14. public class RadioBox extends CheckboxGroup implements ProjLink {
  15.    private ProjBinder m_ProjBinder;
  16.    private RelationView m_relView;
  17.    private String m_projection;
  18.    private int m_treatBlankAs;
  19.    private boolean m_DynamicUpdate = false;
  20.    private Vector rbkVector = new Vector();
  21.    private Container m_Container;
  22.  
  23.    public RadioBox(Container c) {
  24.       this.m_Container = c;
  25.    }
  26.  
  27.    public void init(ProjBinder binder) {
  28.       this.m_ProjBinder = binder;
  29.    }
  30.  
  31.    public RelationView getRelView() {
  32.       return this.m_relView;
  33.    }
  34.  
  35.    public String getProjection() {
  36.       return this.m_projection;
  37.    }
  38.  
  39.    public void setTreatBlankAs(String blank) {
  40.       if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
  41.          this.m_treatBlankAs = 0;
  42.       } else if ((new String(blank)).toUpperCase().equals("NULL")) {
  43.          this.m_treatBlankAs = 1;
  44.       } else {
  45.          if ((new String(blank)).toUpperCase().equals("EMPTY")) {
  46.             this.m_treatBlankAs = 2;
  47.          }
  48.  
  49.       }
  50.    }
  51.  
  52.    public void setBinding(RelationView relView, String projection) {
  53.       this.m_relView = relView;
  54.       this.m_projection = projection;
  55.  
  56.       try {
  57.          int projectionNumber = relView.findProjByName(projection);
  58.          relView.bindProj(projectionNumber, this);
  59.       } catch (SQLException Ex) {
  60.          this.raiseException("SQLException from RadioBox.setBinding: " + ((Throwable)Ex).getMessage());
  61.       }
  62.    }
  63.  
  64.    void addCheckboxes(Container c) {
  65.       int compCnt = c.countComponents();
  66.       Component[] compArray = new Component[compCnt];
  67.       compArray = c.getComponents();
  68.  
  69.       for(int loops = 0; loops < compArray.length; ++loops) {
  70.          if (compArray[loops] instanceof RadioButton) {
  71.             this.rbkVector.addElement(compArray[loops]);
  72.          }
  73.       }
  74.  
  75.    }
  76.  
  77.    public void notifyDataChange(ProjBinder binder) {
  78.       int rbCurrent = 0;
  79.       boolean itemfound = false;
  80.       this.addCheckboxes(this.m_Container);
  81.  
  82.       try {
  83.          while(rbCurrent < this.rbkVector.size()) {
  84.             RadioButton rb = (RadioButton)this.rbkVector.elementAt(rbCurrent);
  85.             if (rb != null) {
  86.                if (((Checkbox)rb).getLabel().equals(binder.getStringValue())) {
  87.                   itemfound = true;
  88.                   break;
  89.                }
  90.  
  91.                ++rbCurrent;
  92.             }
  93.          }
  94.       } catch (SQLException Ex) {
  95.          this.raiseException("SQLException from RadioBox.notifyDataChange: " + ((Throwable)Ex).getMessage());
  96.       } catch (IOException Ex) {
  97.          this.raiseException("IOException from RadioBox.notifyDataChange: " + ((Throwable)Ex).getMessage());
  98.       }
  99.  
  100.       if (!itemfound) {
  101.          ((CheckboxGroup)this).setCurrent((Checkbox)null);
  102.       }
  103.  
  104.    }
  105.  
  106.    public boolean notifySetData(ProjBinder binder) throws SQLException {
  107.       return this.notifyStateChange();
  108.    }
  109.  
  110.    boolean notifyStateChange() {
  111.       if (((CheckboxGroup)this).getCurrent() == null) {
  112.          try {
  113.             if (this.m_ProjBinder != null && this.m_ProjBinder.isWritable()) {
  114.                this.m_ProjBinder.setValueFromString("", 0, this.m_treatBlankAs);
  115.             }
  116.          } catch (SQLException Ex) {
  117.             this.raiseException("SQLException from RadioBox.notifyStateChange: " + ((Throwable)Ex).getMessage());
  118.             return false;
  119.          } catch (IOException Ex) {
  120.             this.raiseException("IOException from RadioBox.notifyStateChange: " + ((Throwable)Ex).getMessage());
  121.             return false;
  122.          }
  123.       }
  124.  
  125.       return true;
  126.    }
  127.  
  128.    void raiseException(String text) {
  129.       System.out.println(text);
  130.    }
  131.  
  132.    public void setDynamicUpdate(boolean update) {
  133.       this.m_DynamicUpdate = update;
  134.    }
  135. }
  136.